# -*- coding: utf-8 -*-
# ogr2ogr ma.shp -t_srs "EPSG:4326" ../data/market.shp

import sys
from osgeo import ogr

dataset = ogr.Open(sys.argv[1])

spatialLayer = ogr.CreateGeometryFromWkt("POLYGON((116.40014648437500 39.90552253633076, 116.40014648437500 39.90973623113919, 116.40563964843750 39.90973623113919, 116.40563964843750  39.90552253633076, 116.40014648437500 39.90552253633076))")

for iLayer in range(dataset.GetLayerCount()):
    layer = dataset.GetLayer(iLayer)
    layer.SetSpatialFilter(spatialLayer)
    while True:
        feature = layer.GetNextFeature()
        if (feature is None):
            break
        for i in range(feature.GetFieldCount()):
            print feature.GetFieldDefnRef(i).GetName() + " : " + feature.GetFieldAsString(i)
        print feature.GetGeometryRef().ExportToJson()

